﻿<cfscript>
    view = createObject("component", "#session.rootDir#.views.layout");
    view.init("Dynamic Group Management", 
        "/jquery/plugins/tablesorter/jquery.tablesorter.min.js, /#session.rootDir#/static/js/allusers.js", "", main);
    view.setSideBar("noSidebar");
    view.html();        
</cfscript>


<cffunction name="main" access="public" output="true" returntype="any">
    <cfscript>
        AllUsers = createObject("component", "#session.rootDir#.objects.Users").init();
        AjaxController = '/#session.rootDir#/controller/AjaxHandler.cfm';
        UsersQuery = new query();
        UsersQuery.setAttributes(GetAllUsers = AllUsers.getAllADUsers());
        users = UsersQuery.execute(sql = "SELECT * FROM GetAllUsers ORDER BY displayName DESC", dbtype="query");
        GetAllUsers = users.getResult();
        ViewUser = "/#session.rootDir#/users/viewuser.cfm?ADUser=";
        ViewGroup = "/#session.rootDir#/groups/viewgroup.cfm?ADGroup="; 
    </cfscript>
    <input type="hidden" id="ViewUser" value="#ViewUser#"/ >
    <input type="hidden" id="ViewUser" value="#ViewGroup#"/ >
    <h3>AD Users #GetAllUsers.RecordCount#</h3>
    <table class="tablesorter dataTable" id="users">
        <thead>
        <tr>
            <th>User Account</th>
            <th>Name</th>
            <th>Title</th>
            <th>Office</th>
            <th>Department</th>
            <th>Manager</th>
        </tr>
        </thead>
        <tbody>
            <cfloop query="GetAllUsers">
                <tr>
                    <td><a href="#ViewUser##trim(sAMAccountName)#">#sAMAccountName#</a></td>
                    <td>#displayName#</td>
                    <td>#( title EQ "" ? '[None]' : title)#</td>
                    <td>#( physicalDeliveryOfficeName EQ "" ? '[None]' : physicalDeliveryOfficeName)#</td>
                    <td>#( department EQ "" ? '[None]' : department)#</td>
                    <cfset Manager = AllUsers.SCFAD.getAccountNameByDN(manager) />
                    <td>#( AllUsers.SCFAD.getAccountNameByDN(manager) EQ "" ? '[None]' : 
                        '<a href="#ViewUser##trim(Manager)#">#AllUsers.SCFAD.getAccountNameByDN(manager)#' )#</td>
                </tr>
            </cfloop>
        </tbody>
    </table>
</cffunction>
